# -*- coding:utf8 -*-
import os
import sys
class BatchRename():
    '''''
    批量重命名文件夹中的图片文件
    '''

    def __init__(self):
        # 给定目标目录
        self.path = '/home/c4isr/下载/anchor'

    def rename(self):
        filelist = os.listdir(self.path)
        total_num = len(filelist)
        i = 294
        n = 6
        for item in filelist:
            if item.endswith('.jpg'):
                n = 6 - len(str(i))
                src = os.path.join(os.path.abspath(self.path), item)
                dst = os.path.join(os.path.abspath('/home/c4isr/下载/new_anchor'), str(0) * n + str(i) + '.jpg')
                try:
                    os.rename(src, dst)
                    # print （'converting %s to %s ...' % (src, dst)  ）
                    i = i + 1
                except:
                    continue


if __name__ == '__main__':
    demo = BatchRename()
    demo.rename()